#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lex.yy.c"
#include "midcode.h"
int myerror = 0;
NODE *root;
NODE *child[10];
InterCode ichead;

int main(int argc, char **argv)
{
    FILE *f;
    if (argc <= 1)
        f = fopen("/home/ubuntu/study/compiler/lab3/test", "r");
    else
        f = fopen(argv[1], "r");
    if (!f)
    {
        perror(argv[1]);
        return 1;
    }
    // yydebug = 1;
    yyrestart(f);
    yyparse(); //生成语法树
    fclose(f);
    char *temp = (char *)malloc(10);
    sprintf(temp, "%s.ir", argv[1]);
    f = fopen(temp, "w");
    if (myerror)
        return 1;
    //语义自顶向下分析过程，从Program文法符号开始
    Program(root);
    if (myerror)
        return 1;
    //利用已有符号表，建立中间代码
    trans_Program(root);
    outputInterCode(f);
    fclose(f);
    return 0;
}
